/*
	highlighted-word-tracker <http://code.google.com/p/highlighted-word-tracker/>
	@version  0.1
 	@author   Sam George on 2011-02-03
	Licence CC-BSD <http://creativecommons.org/licenses/BSD/>
*/
window.onload = function() {
	var sel_text = null;
	var max_querylen = 60;
	var min_len = 3;
    var b = document.getElementsByTagName("body")[0];
    if (b) {
        b.onmouseup = function(c) {         	
			sel_text = getText();
          	f = sel_text.length;
          	d = cnt(sel_text);

            if (sel_text != null && d < max_querylen && f > min_len) {
				pageTracker._trackEvent('CopyText','Highlighted', sel_text);
           }
			
			function cnt(b) {
			    var d = b;
			    var c = 0;
			    a = d.replace(/\s/g, " ");
			    a = a.split(" ");
			    for (z = 0; z < a.length; z++) {
			        if (a[z].length > 0) {
			            c++
			        }
			    }
			    return c
			};
			
			function getText(){
				    if (window.getSelection) {
				        d = window.getSelection()
				    } else {
				        if (document.getSelection) {
				            d = document.getSelection()
				        } else {
				            if (document.selection) {
				                d = document.selection.createRange().text
				            } else {
				                return '';
				            }
				        }
				    }
					return d.toString();
				}
        }
    }
}